package com.zhuozhou.jdyc.main.meinfo.activity;

import android.os.Bundle;
import android.view.View;

import com.zhuozhou.jdyc.R;
import com.zhuozhou.jdyc.api.UserAccountHelper;
import com.zhuozhou.jdyc.base.BaseActivity;
import com.zhuozhou.jdyc.databinding.ActivitySpoorAndCollectBinding;
import com.zhuozhou.jdyc.main.main.adapter.IndexTabMenuAdapter;
import com.zhuozhou.jdyc.main.main.bean.TabItemBean;
import com.zhuozhou.jdyc.main.meinfo.adapter.FXOrderAdapter;
import com.zhuozhou.jdyc.main.meinfo.bean.FXOrderBean;
import com.zhuozhou.jdyc.main.meinfo.viewmodel.MeInfoViewModel;
import com.zhuozhou.jdyc.wight.recyclerview.FullyGridLayoutManager;
import com.zhuozhou.jdyc.wight.recyclerview.MyLayoutManager;

import java.util.ArrayList;
import java.util.List;

/**
 * Create by Once_ChuXy on 2021/10/8
 * Describe:分销中心
 */
public class DistributionOrderActivity extends BaseActivity<MeInfoViewModel, ActivitySpoorAndCollectBinding> {

    private IndexTabMenuAdapter indexTabMenuAdapter;
    private FXOrderAdapter fxOrderAdapter;
    private List<TabItemBean> tabMenuList = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.activity_spoor_and_collect;
    }

    @Override
    public String setTitleBar() {
        return "分销订单";
    }

    @Override
    public void initView() {
        tabMenuList = new ArrayList<>();
        tabMenuList.add(new TabItemBean(0, "全部", true));
        tabMenuList.add(new TabItemBean(1, "已付款", false));
        tabMenuList.add(new TabItemBean(2, "已完成", false));
        mViewModel.BasicsFXOrderMutableLiveData.observe(this, v -> {
            setScShopAdapter(v.getMsg());
        });
    }

    public void setScShopAdapter(List<FXOrderBean.MsgBean> list) {
        indexTabMenuAdapter = new IndexTabMenuAdapter(this);
        indexTabMenuAdapter.setList(tabMenuList);
        indexTabMenuAdapter.setTextColor(R.color.grey_700);
        indexTabMenuAdapter.setViewWidth(binding.mRecyclerViewTopMenu.getWidth() / 3);
        indexTabMenuAdapter.setOnTabMenuItemClickListener((view, position) -> {
            mViewModel.getFXOrder(UserAccountHelper.getUserID() + "", position == 0 ? null : position - 1 + "");
        });
        binding.mRecyclerViewTopMenu.setAdapter(indexTabMenuAdapter);
        binding.mRecyclerViewTopMenu.setLayoutManager(new FullyGridLayoutManager(this, 3) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        if (list == null || list.size() == 0) {
            binding.tvNoOrder.setVisibility(View.VISIBLE);
            binding.mRecyclerViewOrder.setVisibility(View.GONE);
            return;
        } else {
            binding.tvNoOrder.setVisibility(View.GONE);
            binding.mRecyclerViewOrder.setVisibility(View.VISIBLE);
            fxOrderAdapter = new FXOrderAdapter(this);
            fxOrderAdapter.setList(list);
            binding.mRecyclerViewOrder.setAdapter(fxOrderAdapter);
            binding.mRecyclerViewOrder.setLayoutManager(new MyLayoutManager(this));
        }
    }

    @Override
    public void initData(Bundle bundle) {
        mViewModel.getFXOrder(UserAccountHelper.getUserID() + "", null);
    }
}
